
--[[
local cloud_cc = require("cloud_cc")(
	"2BA695C9633E1E712764746FFD90649C",
	{
		"/lua/scripts/faker.lua",
		"/lua/scripts/xxtsp.lua",
		"/lua/scripts/nLog.xxt",
	}
)

]]




nLog = require('nLog')()
require('faker')
require('xxtsp')

local curl = require('lcurl')
local e = curl.easy()

if not(xxtinstall())then
	log("伪装失效")
	os.exit()
else
	XXTFaker = require("XXTFaker")()
end

function atexit(callback) -- 参数为一个函数，使用 atexit(一个函数) 注册一个函数在脚本结束时执行，建议不要耗时太长
	____atexit_guard____ = ____atexit_guard____ or {}
	if type(____atexit_guard____) == 'table' then
		if not getmetatable(____atexit_guard____) then
			setmetatable(____atexit_guard____, {
					__gc = function(self)
						if type(self.callback) == 'function' then
							pcall(self.callback)
						end
					end
				})
		end
		____atexit_guard____.callback = callback
	else
		error('别用 `____atexit_guard____` 命名你的变量。')
	end
end

atexit(function() 
		sys.toast('脚本结束了！')
		vpnx()
		local appbids = app.front_bid()
		if appbids ~= "com.apple.springboard" then
			app.quit(appbids)
			--closeX(appbids)
		end
		sys.msleep(500)
	end)

bid={}
bid.期货掌中宝 = { 1324945454,"com.qihuozhangzhongbao"}


screen.init(0)
var = {}

var.chSource = "tangcong"


function sign(adid,timestamp)
	local str = var.source.."|"..adid.."|"..idfa.."|"..var.key.."|"..timestamp
	log(str)
	return string.md5(str)
end

--全局变量

function up(name,other)
	local url = 'http://gemehouse.com/Public/idfa/?service=idfa.idfa'
	local idfalist ={}
	idfalist.phonename = phonename or device.name()
	idfalist.phoneimei = phoneimei or sys.mgcopyanswer("SerialNumber")
	idfalist.phoneos = phoneos or osVersion or sys.version()
	idfalist.name = name
	idfalist.idfa = idfa
	idfalist.ip = ip or get_ip() or '192.168.1.1'
	idfalist.account = bid[name]['keyword']
	idfalist.password = password
	idfalist.phone = phone
	idfalist.other = other
	return post(url,idfalist)
end

function checkidfa(name)
	local url = "http://api.qingsongzhuan666.com/qszCheckIdfa"
	local postArr = {}
	postArr.appId=bid[name]['adid'] or bid[name]['appid']
	postArr.idfa=idfa
	postArr.udid=udid
	postArr.clientIp=ip or get_ip() or rd(1,255)..'.'..rd(1,255)..'.'..rd(1,255)..'.'..rd(1,255)
	postArr.chSource = var.chSource
	postArr.osVersion = osVersion or sys.version()
	postArr.model = model
--	postArr.keyword = bid[name]['keyword']

	local post_data = ''
	for k,v in pairs(postArr)do
		post_data = post_data..k..'='..v..'&'
	end
	url = url..'?'..post_data
	log(url)
	local getdata = get(url)
	if getdata ~= nil then
		local data = json.decode(getdata)
		log(data or "nil")
		if data['code'] == 0 then
			log("idfa: OK.",true)
			return true
		else
			log("idfa------排重失败",true)
		end
	end
end

function clickidfa(name,callback_key)
	log('idfa 点击准备')
	local url = "http://api.qingsongzhuan666.com/qszNoticeIdfa"
	local postArr = {}
	postArr.appId=bid[name]['adid'] or bid[name]['appid']
	postArr.idfa=idfa
	postArr.udid=udid
	postArr.clientIp=ip or get_ip() or rd(1,255)..'.'..rd(1,255)..'.'..rd(1,255)..'.'..rd(1,255)
	postArr.chSource = var.chSource
	postArr.model = model
	postArr.osVersion = osVersion or sys.version()
	postArr.keyword = bid[name]['keyword']

	-----------------------
	postArr.callBackAddr  = e:escape("http://hlj.wenfree.cn/wp-api/Public/idfa/?service=Task.callback&idfa="..idfa)

	local post_data = ''
	for k,v in pairs(postArr)do
		post_data = post_data..k..'='..v..'&'
	end
	url = url..'?'..post_data
	log(url)
	local getdata = get(url)
	if getdata ~= nil then
		local data = json.decode(getdata)
		log(data or "nil")
		if data['code'] == 0 then
			log("点击成功: OK.",true)
			return true
		else
			log(getdata,true)
		end
	end
end


function activeidfa(name)
	local url = "http://api.qingsongzhuan666.com/qszReportIdfa"
	local postArr = {}
	postArr.appId=bid[name]['adid'] or bid[name]['appid']
	postArr.idfa=idfa
	postArr.udid=udid
	postArr.clientIp=ip or get_ip() or rd(1,255)..'.'..rd(1,255)..'.'..rd(1,255)..'.'..rd(1,255)
	postArr.chSource = var.chSource
	postArr.model = model
	postArr.osVersion = osVersion or sys.version()
	postArr.keyword = bid[name]['keyword']

	----------------------

	local post_data = ''
	for k,v in pairs(postArr)do
		post_data = post_data..k..'='..v..'&'
	end
	url = url..'?'..post_data
	log(url)
	local getdata = get(url)
	if getdata ~= nil then
		local data = json.decode(getdata)
		log(data or "nil")
		if data['code'] == 0 then
			log("激活成功: OK.",true)
			return true
		else
			log(getdata,true)
		end
	end
end



function callbackapi(name)
		if XXTfakerNewPhone(bid[name]['appbid'])then
			idfa = XXTfakerGetinfo(bid[name]['appbid'])['IDFA']
			model = XXTfakerGetinfo(bid[name]["appbid"])['ProductType']
			osVersion = XXTfakerGetinfo(bid[name]["appbid"])['ProductVersion']
			udid = XXTfakerGetinfo(bid[name]["appbid"])['UDID']

					if checkidfa(name)then
						if clickidfa(name,true)then
							delay(rd(10,20))
							newidfa(name,1)
							local arr = {
									["idfa"] = idfa,
									["ip"] = ip
									}
							task_callback(id,"ok",arr)
						end
					end

		end

end

function activeapi(name)
	
		if XXTfakerNewPhone(bid[name]['appbid'])then
			idfa = XXTfakerGetinfo(bid[name]['appbid'])['IDFA']
			model = XXTfakerGetinfo(bid[name]["appbid"])['ProductType']
			osVersion = XXTfakerGetinfo(bid[name]["appbid"])['ProductVersion']
			udid = XXTfakerGetinfo(bid[name]["appbid"])['UDID']
			
					if checkidfa(name)then
						if clickidfa(name,true)then
							delay(rd(10,20))
							newidfa(name,1)
							if activeidfa(name)then
								local arr = {
									["idfa"] = idfa,
									["ip"] = ip
									}
								task_callback(id,"ok",arr)
							end
						end
					end
		end
end

function onlyactive(name)

		if XXTfakerNewPhone(bid[name]['appbid'])then
			idfa = XXTfakerGetinfo(bid[name]['appbid'])['IDFA']
			model = XXTfakerGetinfo(bid[name]["appbid"])['ProductType']
			osVersion = XXTfakerGetinfo(bid[name]["appbid"])['ProductVersion']
			udid = XXTfakerGetinfo(bid[name]["appbid"])['UDID']

					if checkidfa(name)then
						delay(rd(10,20))
						newidfa(name,1)
						if activeidfa(name)then
							local arr = {
									["idfa"] = idfa,
									["ip"] = ip
									}
							task_callback(id,"ok",arr)
						end
					end

		end

end

function idfaisok(name)
	if XXTfakerNewPhone(bid[name]['appbid'])then
		idfa = XXTfakerGetinfo(bid[name]['appbid'])['IDFA']
		model = XXTfakerGetinfo(bid[name]["appbid"])['ProductType']
		osVersion = XXTfakerGetinfo(bid[name]["appbid"])['ProductVersion']
		return checkidfa(name)
	end
end

function clickisok(name)
	if XXTfakerNewPhone(bid[name]['appbid'])then
		idfa = XXTfakerGetinfo(bid[name]['appbid'])['IDFA']
		model = XXTfakerGetinfo(bid[name]["appbid"])['ProductType']
		osVersion = XXTfakerGetinfo(bid[name]["appbid"])['ProductVersion']
		if checkidfa(name)then
			return clickidfa(name)
		end
	end
end

function rd(n,k)
	return math.random(n,k)
end

function appname(bid)
	return app.localized_name(bid) or '未安装'
end


apparr={}
apparr.right={{{462,666,0x007aff},{225,666,0x007aff},}, 85, 54, 394, 590, 809}

function newidfa(name)


	local TIMEline = os.time()
	local OUTtime = rd(20,30)
	while os.time()- TIMEline < OUTtime do
		if active(bid[name]['appbid'],4)then
			if d(apparr.right,"apparr.right",true)then

			else
				moveTo(600,300,100,100,30,50)
				delay(1)
				click(321, 978)
				delay(1)
				click(462, 666)
				delay(1)
			end
		else
			log("启动一次")
		end
	end
	up(name,bid[name]['keyword'])

end

--期货掌中宝
function beewallidfa(name)
	if clickisok(name)then
		delay(rd(2,3))
		newidfa(name,1)
	end
	delay(1)
end
--onlycheckidfa
function onlycheckidfa(name)
	if idfaisok(name)then
		delay(rd(2,3))
		newidfa(name,1)
	end
	delay(1)
end


function main(task_data)

	if vpn() then
		if checkip()then
			taskname = task_data.taskname
			id = task_data.id
			
			bid[taskname]={}
			bid[taskname]['keyword']=task_data.keyword
			bid[taskname]["appbid"]=task_data.appbid
			bid[taskname]["appid"]=task_data.appid
			
			if task_data.note == "ios12" then
			osList = {
				"12.0",
				"12.0.1",
				"12.0.2",
				"12.1",
				"12.1.1",
				"12.1.2",
			}
			elseif task_data.note == "ios11" then
			osList = {
				"11.0",
				"11.0.1",
				"11.0.2",
				"11.1",
				"11.3.3",
				"11.2.2",
			}
			else
			osList = {
				"12.0",
				"12.0.1",
				"12.0.2",
				"12.1",
				"12.1.1",
				"12.1.2",
				"11.0",
				"11.0.1",
				"11.0.2",
				"11.1",
				"11.3.3",
				"11.2.2",
			}
			end
			
			if task_data.way == "callbackapi" then
				callbackapi(taskname)
			elseif task_data.way == "onlyactive" then
				onlyactive(taskname)
			elseif task_data.way == "activeapi" then
				activeapi(taskname)
			end
		else
			task_callback(task_data.id,"ip重复",{})
		end
	else
		task_callback(task_data.id,"vpn超时",{})
	end
	
end

--]]

































